//
//  TimeView.m
//  TodatPlay
//
//  Created by dllo on 16/9/14.
//  Copyright © 2016年 DM.C. All rights reserved.
//

#import "TimeView.h"
#import "TodayLineTableViewCell.h"
#import "TodayTimeTableViewCell.h"


#define kTableViewTimeReuse @"TimeReuse"
#define kTableViewLineReuse @"LineReuse"
@interface TimeView ()<UITableViewDataSource, UITableViewDelegate>
@property (nonatomic, strong) UITableView *tableView;
@end

@implementation TimeView
- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self createTableView];
    }
    return self;
}
- (void)createTableView {
    self.tableView = [[UITableView alloc] initWithFrame:self.bounds style:UITableViewStylePlain];
    [self addSubview:_tableView];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    
        //去掉分割线
    _tableView.separatorStyle = UITableViewCellSelectionStyleNone;
    _tableView.bounces = NO;
    _tableView.showsVerticalScrollIndicator = NO;
    
    [self.tableView registerNib:[UINib nibWithNibName:@"TodayLineTableViewCell" bundle:nil] forCellReuseIdentifier:kTableViewLineReuse];
    [self.tableView registerNib:[UINib nibWithNibName:@"TodayTimeTableViewCell" bundle:nil] forCellReuseIdentifier:kTableViewTimeReuse];
    
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 120;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.row < 5) {
        if (indexPath.row == 0) {
            TodayTimeTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kTableViewTimeReuse];
            cell.timeLabel.text = [NSString stringWithFormat:@"0%ld:00", indexPath.row];
            cell.dayAndNightLabel.text = @"AM";
            return cell;
        } else {
            TodayLineTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kTableViewLineReuse];
            
            return cell;
        }
    } else {
        if (indexPath.row % 5 == 0) {
            if (indexPath.row < 50) {
                TodayTimeTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kTableViewTimeReuse];
                cell.timeLabel.text = [NSString stringWithFormat:@"0%ld:00", indexPath.row / 5];
                cell.dayAndNightLabel.text = @"AM";
                return cell;
            } else if (indexPath.row == 50 || indexPath.row == 60 || indexPath.row == 55 ){
                TodayTimeTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kTableViewTimeReuse];
                cell.timeLabel.text = [NSString stringWithFormat:@"%ld:00", indexPath.row / 5];
                cell.dayAndNightLabel.text = @"AM";
                return cell;
            } else {
                TodayTimeTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kTableViewTimeReuse];
                cell.timeLabel.text = [NSString stringWithFormat:@"%ld:00", indexPath.row / 5];
                cell.dayAndNightLabel.text = @"PM";
                return cell;
            }
        } else {
            TodayLineTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kTableViewLineReuse];
            
            return cell;
        }
    }
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 20;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.row < 5) {
        if (indexPath.row == 0) {
            NSLog(@"点了%ld", indexPath.row);
        }
    } else  {
        if (indexPath.row % 5 == 0) {
            NSLog(@"点了%ld", indexPath.row);
        }
        
    }
    

}

@end
